﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QL_DTTN.DAL;
namespace QL_DTTN.DTO.DTO
{
   public partial class Truong
    {
       public DataTable dataTable(int maTinh)
       {
           string sql = " select maTruong,tenTruong from " + _tableName + " where MaTinh=@pMaTinh " ;
           SqlDataProvider dp = new SqlDataProvider();
           dp.AddParameter(new SqlParameter("@pMaTinh", maTinh));
           return dp.ExDataTable(sql, true);
       }
       public int getMaTinh(string maTruong)
       {
           string sql = " select maTinh from " + _tableName + " where "+_keyField+"=@pMaTruong ";
           SqlDataProvider dp = new SqlDataProvider();
           dp.AddParameter(new SqlParameter("@pMaTruong", maTruong));
         
           object id = null;
           int kq = 0;
           if (dp.RunReturnSQL(sql, ref id, true))
           {
               if (id.ToString() == "" || id == null)
               {
                   return -1;
               }
               else
               {
                   if (int.TryParse(id.ToString(), out kq))
                   {
                       return kq;
                   }
                   else return -1;
               }
           }
           else return -1;
       }
    }
}
